#include "notesarea.h"

NotesArea::NotesArea(QWidget *parent) : QSplitter(parent)
	{
		setMinimumSize(400, 400);
		setOrientation(Qt::Vertical);
		setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

		listW = new QListWidget(this);
		listW->setHorizontalScrollMode(QListView::ScrollPerPixel);
		listW->setIconSize(QSize(72,72));
		listW->setMinimumHeight(133);
		listW->setSpacing(10);
		listW->setViewMode(QListView::IconMode);
		listW->setWrapping(false);

		mdiArea = new QMdiArea(this);
		mdiArea->setMinimumHeight(250);
		mdiArea->setViewMode(QMdiArea::TabbedView);
		mdiArea->setDocumentMode(true);

		addWidget(listW);
		addWidget(mdiArea);

		connect(listW, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addItem(QListWidgetItem*)));
	}

void NotesArea::addItem(QListWidgetItem *item)
	{
		QString data = item->data(Qt::UserRole).toString();
		NoteEditor *editorWin = new NoteEditor(mdiArea);
		editorWin->setWindowFilePath(data);
		editorWin->attachFile();
		if (editorWin->documentTitle() == "") editorWin->setDocumentTitle(item->text());
		else editorWin->setWindowTitle(editorWin->documentTitle());
	}

QMdiArea *NotesArea::area() const
	{
		return mdiArea;
	}

void NotesArea::switchWidgets(ListPosition pos)
	{
		if (pos == Top || pos == Left) insertWidget(0, listW);
		else insertWidget(1, listW);
	}

QListWidget *NotesArea::view() const
	{
		return listW;
	}
